/*
* 动画管理类
*/
class AniUtil {
    /**
     * 初始化英雄动画
     */
    public static initAnimationGeneral(generalId: number) {
        let icon: number = tb_game.general[generalId].icon;
        let iconnum: number = tb_game.general[generalId].icon_num;
        let anistand = "general" + icon + "stand";
        let anihit = "general" + icon + "hit";
        Laya.Animation.createFrames(this.aniGeneralUrls("stand", icon, 1, 1), anistand);
        Laya.Animation.createFrames(this.aniGeneralUrls("hit", icon, 1, iconnum), anihit);
    }
    private static aniGeneralUrls(aniName: string, icon: number, start: number, end: number) {
        let urls: any = [];
        for (var i: number = start; i <= end; ++i) {
            //动画资源路径要和动画图集打包前的资源命名对应起来
            urls.push("general/general" + icon + "_" + aniName + i + ".png");
        }
        return urls;
    }
    public static playGeneral(ani: Laya.Animation, generalId: number, name: string, loop: boolean = true) {
        let icon: number = tb_game.general[generalId].icon;
        ani.play(0, loop, "general" + icon + name, true);
    }


    /**
    * 初始化怪物动画
    */
    public static initAnimationEnemy(enemyId: number) {
        let icon: number = tb_game.enemy[enemyId].icon;
        let iconnum: number = tb_game.enemy[enemyId].icon_num;

        Laya.Animation.createFrames(this.aniEnemyUrls(Define.Stand, icon, 1, 1), "enemy" + icon + "_" + Define.Stand);
        Laya.Animation.createFrames(this.aniEnemyUrls(Define.LEFT, icon, 1, iconnum), "enemy" + icon + "_" + Define.LEFT);
        Laya.Animation.createFrames(this.aniEnemyUrls(Define.RIGHT, icon, 1, iconnum), "enemy" + icon + "_" + Define.RIGHT);
        Laya.Animation.createFrames(this.aniEnemyUrls(Define.DOWN, icon, 1, iconnum), "enemy" + icon + "_" + Define.DOWN);
        Laya.Animation.createFrames(this.aniEnemyUrls(Define.Hit, icon, 1, iconnum), "enemy" + icon + "_" + Define.Hit);
    }
    private static aniEnemyUrls(aniName: number, icon: number, start: number, end: number) {
        let urls: any = [];
        for (var i: number = start; i <= end; ++i) {
            //动画资源路径要和动画图集打包前的资源命名对应起来
            urls.push("enemy/enemy" + icon + "_" + aniName + "_" + i + ".png");
        }
        return urls;
    }
    public static playEnemy(ani: Laya.Animation, enemyId: number, name: number, loop: boolean = true) {
        let icon: number = tb_game.enemy[enemyId].icon;
        ani.play(0, loop, "enemy" + icon + "_" + name, true);
    }
}